package com.example.owner.lettery1.other;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


/**
 * Created by Administrator on 2016/10/29.
 */
public class TextItemCreator extends ItemCreator {


    public TextItemCreator(Context context) {
        super(context);
    }

    public TextItemCreator(Context context, int... weights) {
        super(context, weights);
    }

    public String getText(String[] texts, int position) {
        return texts == null || position > texts.length - 1 ? "" : texts[position];
    }

    public TextTableViewHolder createItem(String... texts) {
        LinearLayout ll = new LinearLayout(getContext());
        ll.setOrientation(LinearLayout.VERTICAL);
        TextView tvExtraRow = new TextView(getContext());
        tvExtraRow.setTextColor(0xffffffff);
        tvExtraRow.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);
        tvExtraRow.setGravity(Gravity.CENTER);
        tvExtraRow.setPadding(0, 25, 0, 25);
        tvExtraRow.setBackgroundColor(0xffc1c1c1);
        tvExtraRow.setVisibility(View.GONE);
        tvExtraRow.setText("超出入住时间");
        ll.addView(tvExtraRow, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        LinearLayout rowLayout = new LinearLayout(getContext());
        rowLayout.setOrientation(LinearLayout.HORIZONTAL);
        rowLayout.setDividerDrawable(getVerticalDivider());
        rowLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        ll.addView(rowLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        TextTableViewHolder holder = new TextTableViewHolder(ll);

        int count = getCount();
        for (int i = 0; i < count; i++) {
            TextView itemView = new TextView(getContext());
            itemView.setTextColor(0xffc1c1c1);
            itemView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);
            itemView.setGravity(Gravity.CENTER);
            itemView.setPadding(0, 25, 0, 25);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
            params.weight = getWeight(i);
            itemView.setText(getText(texts, i));
            rowLayout.addView(itemView, params);
            holder.addItem(itemView);
        }
        return holder;
    }
}
